﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.DALFactory;

namespace KPIS.GERP.GHRMS.BLL
{
    public class FieldDutyBLL : IFieldDutyBLL
    {
        private static readonly IFieldDutyDAL DAL = DataAccess.CreateFieldDuties();
        //private static readonly IFieldDAL fDAL = DataAccess.CreateFields();
        //private static readonly IClassDAL cDAL = DataAccess.CreateClasses();

        private FieldInfo fInfo = new FieldInfo();
        private ClassInfo cInfo = new ClassInfo();
        private FieldDutyInfo dutyInfo = new FieldDutyInfo();

        //public IList<FieldDutyInfo> ListFieldDuties()
        //{
        //    return DAL.ListFieldDuties(new FieldDutyInfo(0));
        //}
        public IList<FieldDutyInfo> ListFieldDutiesBySequence(int Sequence)
        {
            return DAL.ListFieldDuties(new FieldDutyInfo(Sequence));
        }
        public IList<FieldDutyInfo> ListFieldDuties(string Field, string Class)
        {
            if (Field.Length > 0)
                fInfo.Sequence = Int32.Parse(Field);
            if (Class.Length > 0)
                cInfo.Sequence = Int32.Parse(Class);
            dutyInfo.Field = fInfo;
            dutyInfo.Class = cInfo;
            dutyInfo.Sequence = 0;

            return DAL.ListFieldDuties(dutyInfo);
        }
        public void Insert(string Field, string Class, string Description, string Remarks, int CreatedBy)
        {
            if (Field.Length > 0)
                fInfo.Sequence = Int32.Parse(Field);
            if (Class.Length > 0)
                cInfo.Sequence = Int32.Parse(Class);

            try
            {
                DAL.Insert(new FieldDutyInfo(0, fInfo, cInfo, Description, Remarks, "", CreatedBy, 0));
            }   
            catch
            {
                throw new Exception("");
            }
        }
        public void Update(int Sequence, string Field, string Class, string Description, string Remarks, int UpdatedBy)
        {
            if (Field.Length > 0)
                fInfo.Sequence = Int32.Parse(Field);
            if (Class.Length > 0)
                cInfo.Sequence = Int32.Parse(Class);

            try
            {
                DAL.Update(new FieldDutyInfo(Sequence, fInfo, cInfo, Description, Remarks, "", 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                DAL.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
    }
}
